package wiki.xsx.jg.core;

/**
 * 数据库适配器
 */
public class DatabaseAdapter {
    /**
     * 获取对应的数据库实现类对象
     * @param driverClassName 数据库驱动名称
     * @param dbUrl 数据库地址
     * @param userName 数据库用户名
     * @param password 数据库密码
     * @return 返回数据库实现类对象
     * @throws Exception
     */
    public static DatabaseService getServiceInstance(
            String driverClassName,
            String dbUrl,
            String userName,
            String password
    ) throws Exception {
        DatabaseService service;
        if (driverClassName.contains("mysql")){
            service = new MysqlService(driverClassName, dbUrl, userName, password);
        }else if (driverClassName.contains("oracle")){
            service = new OracleService(driverClassName, dbUrl, userName, password);
        }
//        else if (driverClassName.contains("sqlserver")){
//
//        }else if (driverClassName.contains("sybase")){
//
//        }else if (driverClassName.contains("db2")){
//
//        }
        else{
            throw new Exception("Unsupported database type");
        }
        return service;
    }
}
